#!/bin/bash

echo "---------------------ADSB小工具-----------------------"

while true; do
    echo "请选择一个选项："
    echo
    echo "666. 一键安装 readsb + tar1090 （中文版）+ 飞常准上传"
    echo
    echo "基础与前端服务"
    echo "1. 安装 readsb + tar1090 （中文版）           2. 更新 readsb+tar1090 （中文版）        3. 卸载 readsb+tar1090 （中文版）"
    echo "4. 仅安装 readsb                             5. 仅更新 readsb                         6. 仅卸载 readsb"
    echo "7. 仅安装 tar1090 （中文版）                  8. 仅更新 tar1090 （中文版）              9. 仅卸载 tar1090 （中文版）"
    echo
    echo "上传服务"
    echo "10. 安装飞常准上传          11. 卸载飞常准上传"
    echo
    echo "其他工具"
    echo "12. 自定义 UUID    14. WiFi连接配置    73. 退出脚本"
    echo

    read choice

    case $choice in
    666)
        echo "安装 readsb + tar1090 （中文版）+ 飞常准上传"
        systemctl disable --now readsb
        bash -c "$(wget -O - https://gitee.com/fan0225/ADSB-scripts/raw/main/readsb+tar1090-install.sh)"
        echo "即将开始安装飞常准上传"
        sleep 10
        bash -c "$(wget -nv -O - https://gitee.com/fan0225/ADSB-scripts/raw/main/feeyo.sh)"
        exit
        ;;
    1)
        echo "安装 readsb + tar1090 （中文版）"
        systemctl disable --now readsb
        bash -c "$(wget -O - https://gitee.com/fan0225/ADSB-scripts/raw/main/readsb+tar1090-install.sh)"
        exit
        ;;
    2)
        echo "正在更新 readsb + tar1090 （中文版）"
        if [[ -f /usr/local/share/tar1090/uninstall.sh ]] ; then
        bash /usr/local/share/tar1090/uninstall.sh
        else
        bash -c "$(wget -nv -O - https://gitee.com/fan0225/tar1090-zh/raw/master/uninstall.sh)"
        fi
        systemctl disable --now readsb
        bash -c "$(wget -O - https://gitee.com/fan0225/ADSB-scripts/raw/main/readsb+tar1090-install.sh)"
        exit
        ;;
    3)
        echo "正在卸载 readsb + tar1090 "
        if [[ -f /usr/local/share/tar1090/uninstall.sh ]] ; then
        bash /usr/local/share/tar1090/uninstall.sh
        else
        bash -c "$(wget -nv -O - https://gitee.com/fan0225/tar1090-zh/raw/master/uninstall.sh)"
        fi
        systemctl disable --now readsb
        exit
        ;;
    4)
        echo "正在仅安装 readsb "
        systemctl disable --now readsb
        bash -c "$(wget -O - https://gitee.com/fan0225/ADSB-scripts/raw/main/readsb-install.sh)"
        exit
        ;;
    5)
        echo "正在仅更新 readsb "
        systemctl disable --now readsb
        bash -c "$(wget -O - https://gitee.com/fan0225/ADSB-scripts/raw/main/readsb-install.sh)"
        exit
        ;;
    6)
        echo "正在仅卸载 readsb "
        systemctl disable --now readsb
        exit
        ;;
    7)
        echo "正在仅安装 tar1090 （中文版）"
        bash -c "$(wget -nv -O - https://gitee.com/fan0225/tar1090-zh/raw/master/install.sh)"
        exit
        ;;
    8)
        echo "正在仅更新 tar1090 （中文版）"
        if [[ -f /usr/local/share/tar1090/uninstall.sh ]] ; then
        bash /usr/local/share/tar1090/uninstall.sh
        else
        bash -c "$(wget -nv -O - https://gitee.com/fan0225/tar1090-zh/raw/master/uninstall.sh)"
        fi
        bash -c "$(wget -nv -O - https://gitee.com/fan0225/tar1090-zh/raw/master/install.sh)"
        exit
        ;;
    9)
        echo "正在仅卸载 tar1090 "
        if [[ -f /usr/local/share/tar1090/uninstall.sh ]] ; then
        bash /usr/local/share/tar1090/uninstall.sh
        else
        bash -c "$(wget -nv -O - https://gitee.com/fan0225/tar1090-zh/raw/master/uninstall.sh)"
        fi
        exit
        ;;
    10)
        echo "正在安装飞常准上传 "
        bash -c "$(wget -nv -O - https://gitee.com/fan0225/ADSB-scripts/raw/main/feeyo.sh)"
        exit
        ;;
    11)
        echo "正在卸载飞常准上传 "
        rm -r /root/feeyoadsb
        exit
        ;;   
    12)
        echo "正在自定义 UUID "
        echo
        read -p "请输入你的 UUID：" uuid
        sed -i -e "/你的UUID/s/.*/UUID=$uuid/" /root/feeyoadsb/conf.ini
        sed -i -e "/你的UUID是/s/.*/<a>你的UUID是：$uuid<\/a>/" /usr/local/share/tar1090/html/index.html
        echo
        echo "----替换完成，重启生效----"
        exit
        ;;
    13)
        echo "进入WiFi连接配置"
        sleep 2
        bash -c "$(wget -O - https://gitee.com/fan0225/ADSB-scripts/raw/main/wifi-configuration.sh)"
        exit
        ;;
    73)
        echo "正在退出"
        exit
        ;;
    *)
        echo "无效的选择"
        ;;
    esac
done
